package _022_2_15

//1 0 0 1
//0 1 1 0
//0 1 1 1
//1 0 1 1

func dfs(visited []int, isConnected [][]int, index int, isOk *bool) {
	visited[index] = 1

	for i := 0; i < len(visited); i++ {
		if isConnected[index][i] == 1 && visited[i] != 1 {
			dfs(visited, isConnected, i, isOk)
		}
	}
}

func findCircleNum(isConnected [][]int) int {
	visited := make([]int, len(isConnected))
	isOk := false
	num := 0

	for i := 0; i < len(visited); i++ {
		if visited[i] != 1 {
			dfs(visited, isConnected, i, &isOk)
			num++
		}
	}

	return num
}
